import robomaster
from robomaster import robot
from robomaster import config
from multiprocessing import Process
import multiprocessing
import EP1
import EP2
import TT
import time

#实例化三个类
eP1=EP1.EP1class()
eP2=EP2.EP2class()
t=TT.TT()


def EP1run():
    eP1.catchfangkuai()
    
def EP1Main(EProbot1_target):
    ep1=EProbot1_target.value
    eP1.main(ep1)

def EP2run():
    eP2.catchfangkuai()
   
def EP2Main(EProbot2_target):
    ep2=EProbot2_target.value
    eP2.main(ep2)

def TTrun(EProbot1_target,EProbot2_target):
    EProbot1_target.value,EProbot2_target.value=t.main()
    print('1号工程兵目标已确定为{}号核电站'.format(EProbot1_target.value)) 
    print('2号工程兵目标已确定为{}号核电站'.format(EProbot2_target.value))



if __name__ == "__main__":

    print('begin')

    #两个工程兵的救援目标 数值对应第几号核电站
    EProbot1_target=multiprocessing.Value("i",0)
    EProbot2_target=multiprocessing.Value("i",0)
    #print(EProbot1_target,EProbot2_target)

    #定义几个进程
    process_ep1=multiprocessing.Process(target=EP1run)
    process_ep2=multiprocessing.Process(target=EP2run)
    thread_tt=multiprocessing.Process(target=TTrun,args=(EProbot1_target,EProbot2_target,))
    process_ep1_main=multiprocessing.Process(target=EP1Main,args=(EProbot1_target,))
    process_ep2_main=multiprocessing.Process(target=EP2Main,args=(EProbot2_target,))
    
    #前两个进程两个工程兵先获取方块，之后TT识别目标，最后巡线到核电站放方块和获取核废料放到处理站
    process_ep1.start()
    process_ep2.start()
    thread_tt.start()  
    process_ep1.join()
    process_ep2.join()  
    thread_tt.join()
    process_ep1_main.start()
    process_ep2_main.start()
    process_ep1_main.join()
    process_ep2_main.join()

    print('over')
